//
//  NSDictionary+Extension.m
//  Zero
//
//  Created by 梁炜东 on 16/10/20.
//  Copyright © 2016年 zore. All rights reserved.
//

#import "NSDictionary+Extension.h"
#import <objc/runtime.h>

@implementation NSDictionary (Extension)
-(NSArray *)orderAllKeys
{
    NSArray *arr = [self keysSortedByValueWithOptions:NSSortConcurrent usingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2)
    {
        NSString * str1 = obj1;
        NSString * str2 = obj2;
        return [str1 compare:str2];
    }];
    return arr;
}

+(NSDictionary *)parseJSONStringToNSDictionary:(NSString *)JSONString
{
    NSData *JSONData = [JSONString dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableLeaves error:nil];
    return responseJSON;
}

-(id)keyForObject:(id)value
{
    NSEnumerator *enumerator = [self keyEnumerator];
    id key = nil;
    while (key = [enumerator nextObject])
    {
        id valueOkey = [self objectForKey:key];
        if ([value isKindOfClass:[NSNumber class]])
        {
            if ([value intValue] == [valueOkey intValue])
            {
                return key;
            }
        }
    }
    return nil;
}

@end
